<!DOCTYPE HTML>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>生猪贸易平台</title>
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/bui.css" />
</head>
<style>
    .main-footer {
        background-color: #fff
    }

    .main-footer .btn-home {
        position: relative;
        overflow: visible
    }

    .main-footer .btn-home .big-icon {
        z-index: 10;
        margin-top: -.2rem;
        display: inline-block;
        width: .94rem;
        height: .94rem;
        line-height: .94rem;
        color: #fff;
        border-radius: 50%;
        background: linear-gradient(141.4deg, #02b9fa, #508dff)
    }
    .main-footer .layer1 {
        top: -.3rem;
        left: 50%;
        width: 1.2rem;
        height: 1.2rem;
        position: absolute;
        box-shadow: 0 0 1px 1px #eee;
        border-radius: 50%;
        transform: translateX(-50%);
        background-color: #fff
    }

    .main-footer .layer2 {
        position: absolute;
        top: 0rem;
        bottom: -.05rem;
        width: 100%;
        background-color: #fff
    }
</style>
<body>
    <div class="bui-page">
        <header class="bui-bar">
            <div class="bui-bar-left">
                <!-- 左边有图标示例 -->
<!--                <div class="bui-btn"><i class="icon-back"></i></div>-->
            </div>
            <div class="bui-bar-main">生猪交易平台</div>
            <div class="bui-bar-right">
                <!-- 右边有图标示例 -->
<!--                <div class="bui-btn"><i class="icon-search"></i></div>-->
            </div>
        </header>
        <main>
            <div id="uiTab" class="bui-tab">
                <div class="bui-tab-head">
                    <ul class="bui-nav">
                        <li class="bui-btn">待收款</li>
                        <li class="bui-btn">待付款</li>
                        <li class="bui-btn">订单</li>
                    </ul>
                </div>
                <div class="bui-tab-main">
                    <ul>
                        <!-- 内容必须在li里面 -->
                        <li>
                            <ul class="bui-list">
                                <div class="bui-scroll">
                                    <div class="bui-scroll-head"></div>
                                    <div class="bui-scroll-main">
                                        <ul class="bui-list bui-list-thumbnail" id="dsklb">

                                        </ul>
                                    </div>
                                    <div class="bui-scroll-foot"></div>
                                </div>

                            </ul>
                        </li>
                        <li style="display: none;">
                            <ul class="bui-list">
                                <div class="bui-scroll">
                                    <div class="bui-scroll-head"></div>
                                    <div class="bui-scroll-main">
                                        <ul class="bui-list bui-list-thumbnail" id="dfklb">

                                        </ul>
                                    </div>
                                    <div class="bui-scroll-foot"></div>
                                </div>
                            </ul>
                        </li>
                        <li style="display: none;">
                            <ul class="bui-list">
                                <div id="ywclist" class="bui-scroll">
                                    <div class="bui-scroll-head"></div>
                                    <div class="bui-scroll-main">
                                        <ul class="bui-list bui-list-thumbnail" id="ddlb">

                                        </ul>
                                    </div>
                                    <div class="bui-scroll-foot"></div>
                                </div>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>



        </main>
        <footer class="main-footer">
            <!-- 底部d导航栏 -->
            <ul class="bui-nav">
                <li class="bui-btn bui-box-vertical active"><i class="icon-home"></i>
                    <div class="span1">订单</div>
                </li>
<!--                <li class="bui-btn btn-home bui-box-vertical" id="btnAdd">-->
<!--                    <i class="icon-plus big-icon"></i>-->
<!--                    <span class="layer1"></span><span class="layer2"></span>-->
<!--                </li>-->
                <li class="bui-btn bui-box-vertical" href="my.html"><i class="icon">&#xe67a;</i>
                    <div class="span1">我的</div>
                </li>
            </ul>
        </footer>
    </div>


    <script src="../js/zepto.js"></script>
    <script src="../js/bui.js"></script>
    <!-- 初始化单页 -->
    <script src="../index.js"></script>
    <script src="../js/common.js"></script>
    <script>
        var index = 0;
        function listData(listid,status){
            var yhbm = $$("yhbm");
            var mobile = $$("mobile");
            var storage = bui.storage();
            var lx = storage.get("lx");
            // console.log("lx:"+lx);
            bui.list({
                id: "#"+listid,
                url: BASE_URL+"/front/list",
                pageSize: 10,
                data: {status:status,yhbm:yhbm,type:lx[0],mobile:mobile},
                field: {
                    page: "page",
                    size: "pageSize",
                    data: "data"
                },
                callback: function(e) {
                    // e.target 为你当前点击的元素
                    // e.currentTarget 为你当前点击的handle 整行
                },
                template: function(data) {
                    var html = "";
                    data.forEach(function(el, index) {
                        html += ` <li class="bui-btn bui-box" href="detail.html?ddbm=${el.DDBM}">
                                                <div class="span1">
                                                    <h3 class="item-title">订单编号</h3>
                                                    <p class="item-text"><span class="bui-label">申请人</span><span class="bui-value">XXXX</span></p>
                                                </div>
                                                <i class="icon-listright"></i>
                                            </li>`;
                    });

                    return html;
                },
                onBeforeRefresh: function() {
                    // console.log("brefore refresh")
                },
                onBeforeLoad: function() {
                    // console.log("brefore load")
                },
                onRefresh: function() {
                    // 刷新以后执行
                    // console.log("refreshed")
                },
                onLoad: function() {
                    // 刷新以后执行
                    // console.log("loaded")
                }
            })
        }
        //待收款列表
        function readyCollectMoneyList(){
            var yhbm = $$("yhbm");
            var mobile = $$("mobile");
            var storage = bui.storage();
            var lx = storage.get("lx");

            var ajax = bui.ajax({
                url: BASE_URL+"/front/readyCollectMoneyList",
                // 可选参数
                data: {
                    yhbm:yhbm
                },
                method: "GET"
            });
            ajax.then(function(res) {
                if(res.code == 0){
                    var order  = res.data;
                    if(order){
                        var html = "";
                        for(var i=0;i<order.length;i++){
                          var o = order[i];
                            html += ` <li class="bui-btn bui-box">
                                                <div class="span1">
                                                     <h3 class="item-title"><a href="detail.html?ddbm=`+(o.ddbm||"")+`">订单编号：`+(o.ddbm||"")+`</a></h3>
                                                    <p class="item-text"><span class="bui-label">订单时间</span><span class="bui-value">`+(o.DDSJ||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">收款金额</span><span class="bui-value">`+(o.je||"")+`元</span></p>
                                                    <p class="item-text"><span class="bui-label">收款方式</span><span class="bui-value" style="font-weight: bold">`+(o.fs||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">付款方</span><span class="bui-value">`+(o.XM||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">电话</span><span class="bui-value">`+(o.MOBILE||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">收款状态</span><span class="bui-value"><font color="red">未收款</font></span></p>
                                                    <p class="item-text"><span class="bui-label">收款时间</span><span class="bui-value">`+(o.sj||"")+`</span></p>
                                                </div>
                                            </li>`;

                        }

                        $('#dsklb').html(html);

                    }
                }else{
                    bui.alert(res.msg);
                }
            },function(res) {
                bui.alert("请求异常");
            });

        }
        //待付款列表
        function readyPayMoneyList(){
            var yhbm = $$("yhbm");
            var ajax = bui.ajax({
                url: BASE_URL+"/front/readyPayMoneyList",
                // 可选参数
                data: {
                    yhbm:yhbm
                },
                method: "GET"
            });

            ajax.then(function(res) {
                if(res.code == 0){
                    var order  = res.data;
                    if(order){
                        var html = "";
                        for(var i=0;i<order.length;i++){
                            var o = order[i];
                            html += ` <li class="bui-btn bui-box">
                                                <div class="span1">
                                                    <h3 class="item-title"><a href="detail.html?ddbm=`+(o.ddbm||"")+`">订单编号：`+(o.ddbm||"")+`</a></h3>
                                                    <p class="item-text"><span class="bui-label">订单时间</span><span class="bui-value">`+(o.DDSJ||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">付款金额</span><span class="bui-value">`+(o.je||"")+`元</span></p>
                                                    <p class="item-text"><span class="bui-label">付款方式</span><span class="bui-value" style="font-weight: bold">`+(o.fs||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">收款方</span><span class="bui-value">`+(o.XM||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">电话</span><span class="bui-value">`+(o.MOBILE||"")+`</span></p>
                                                    <p class="item-text"><span class="bui-label">付款状态</span><span class="bui-value"><font color="red">未付款</font></span></p>
                                                    <p class="item-text"><span class="bui-label">付款时间</span><span class="bui-value">`+(o.sj||"")+`</span></p>
                                                </div>
                                                <div class="bui-interval">
                                                    <div class="bui-btn primary"  onclick="doPay();" >付款</div>
                                                </div>
                                            </li>`;

                        }

                        $('#dfklb').html(html);

                    }
                }else{
                    bui.alert(res.msg);
                }
            },function(res) {
                bui.alert("请求异常");
            });
        }

        function orderList(){
            var yhbm = $$("yhbm");

            bui.list({
                id: "#ywclist",
                url: BASE_URL+"/front/orderList",
                pageSize: 10,
                data: {yhbm:yhbm},
                field: {
                    page: "page",
                    size: "pageSize",
                    data: "data"
                },
                callback: function(e) {
                    // e.target 为你当前点击的元素
                    // e.currentTarget 为你当前点击的handle 整行
                },
                template: function(data) {
                    var html = "";
                    data.forEach(function(el, index) {
                        html += ` <li class="bui-btn bui-box" href="detail.html?ddbm=${el.DDBM}">
                                                <div class="span1">
                                                    <h3 class="item-title">订单编号：${el.DDBM}</h3>
                                                    <p class="item-text"><span class="bui-label">订单时间</span><span class="bui-value">${el.DDSJ}</span></p>
                                                </div>
                                                <i class="icon-listright"></i>
                                            </li>`;
                    });

                    return html;
                },
                onBeforeRefresh: function() {
                    // console.log("brefore refresh")
                },
                onBeforeLoad: function() {
                    // console.log("brefore load")
                },
                onRefresh: function() {
                    // 刷新以后执行
                    // console.log("refreshed")
                },
                onLoad: function() {
                    // 刷新以后执行
                    // console.log("loaded")
                }
            })
        }

        function doPay(){
            if(bui){


                bui.confirm("确认要付款么？", function(e) {
                    var text = $(e.target).text();
                    if (text == "确定") {
                        //执行登录操作
                        var yhbm = $$("yhbm");


                        // var addAjax = bui.ajax({
                        //     url: BASE_URL+"/front/addOrder",
                        //     // 可选参数
                        //     data: {
                        //         yhbm:yhbm
                        //     },
                        //     method: "POST"
                        // });
                        // addAjax.then(function(res) {
                        //     if(res.code == 0){
                        //         var user = res.data;
                        //         bui.alert("订单发起成功");
                        //         window.location.reload();
                        //     }else{
                        //         bui.alert(res.msg);
                        //     }
                        // },function(res) {
                        //     bui.alert("请求异常");
                        // })
                        // console.log("你点击了" + $(e.target).text())
                    }
                    this.close()
                });
            }
        }
        bui.ready(function () {

            initCommon(bui);

            var lx = $$("lx");
            if(lx != 1){
                $("#btnAdd").hide();
            }
            // console.log(lx);

            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();

            var uiTab = bui.tab({
                id:"#uiTab"
            });

            var storage = bui.storage();
            var lx = storage.get("lx");
            if(lx == 2 || lx == 0 || lx==3){
                $("#btnAdd").hide();
            }


            $("#paybtn").on("click",function () {
                bui.confirm("确认要付款么？", function(e) {
                    var text = $(e.target).text();
                    if (text == "确定") {
                        //执行登录操作
                        var yhbm = $$("yhbm");


                        // var addAjax = bui.ajax({
                        //     url: BASE_URL+"/front/addOrder",
                        //     // 可选参数
                        //     data: {
                        //         yhbm:yhbm
                        //     },
                        //     method: "POST"
                        // });
                        // addAjax.then(function(res) {
                        //     if(res.code == 0){
                        //         var user = res.data;
                        //         bui.alert("订单发起成功");
                        //         window.location.reload();
                        //     }else{
                        //         bui.alert(res.msg);
                        //     }
                        // },function(res) {
                        //     bui.alert("请求异常");
                        // })
                        // console.log("你点击了" + $(e.target).text())
                    }
                    this.close()
                });
            });

            readyCollectMoneyList();

            readyPayMoneyList();

            orderList();


        });
    </script>

</body>

</html>